﻿using System;
using System.Linq;
using GalaSoft.MvvmLight.Command;
using NetBay.Core.BusinessEntities;
using Rio.Framework.Localisation;
using Rio.Framework.Pages.AppCode.Enums;
using Rio.Framework.Pages.Context;
using Rio.Framework.Pages.Events;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.RibbonView;
using System.Collections.ObjectModel;
using Rio.Framework.Pages.Controls.Navigation;

namespace Rio.Framework.Pages.Controls
{
    /// <summary>
    /// This class manage the state of all button available in the Ribbon bar
    /// </summary>
    public partial class DocumentRibbonBar
    {
        private const string format = "/Rio.Framework.Pages;component/Assets/Images/Viewer/{0}";
        private ObservableCollection<TabViewModel> _tabs;
        private ObservableCollection<ButtonViewModel> _quickAccessButtons;

        #region Properties

        /// <summary>
        /// Gets the tabs.
        /// </summary>
        /// <value>The tabs.</value>
        public ObservableCollection<TabViewModel> Tabs
        {
            get
            {
                return _tabs;
            }
        }

        /// <summary>
        /// Gets the quick access buttons.
        /// </summary>
        /// <value>The quick access buttons.</value>
        public ObservableCollection<ButtonViewModel> QuickAccessButtons
        {
            get
            {
                return _quickAccessButtons;
            }
        }

        #endregion

        #region Events
        public delegate void DocumentRibbonBarEventHandler(object sender, DocumentRibbonBarEventArgs args);
        public event DocumentRibbonBarEventHandler DocumentRibbonBarEvent;
        public RelayCommand<string> ClickCommand { get; set; }
        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="DocumentRibbonBar" /> class.
        /// </summary>
        public DocumentRibbonBar()
        {
            InitializeComponent();
            ClickCommand = new RelayCommand<string>(RaiseClickEvent, CanExecute);
            ScanImportIsEnabled = true;
            _quickAccessButtons = new ObservableCollection<ButtonViewModel>();
        }

        #endregion

        #region Public

        /// <summary>
        /// Manages the toolbar.
        /// </summary>
        public void ManageToolbar()
        {
            BuildToolbar();
            ClickCommand.RaiseCanExecuteChanged();
        }

        /// <summary>
        /// Set user priviledges
        /// </summary>
        /// <param name="p_oFolderType"></param>
        /// <param name="p_oOrganization"></param>
        public void SetUserPriviledges(FolderType p_oFolderType, Organization p_oOrganization)
        {
            CanModify = GlobalWebContext.GetUserCanModify(p_oFolderType);
            CanDelete = GlobalWebContext.GetUserCanDelete(p_oFolderType);
            CanDownload = GlobalWebContext.GetUserCanDownload(p_oFolderType);
            CanPrint = GlobalWebContext.GetUserCanPrint(p_oFolderType);
            CanSendMail = GlobalWebContext.GetUserCanSendMail(p_oFolderType);
            CanImport = GlobalWebContext.GetUserCanImport(p_oOrganization, p_oFolderType);
            CanTrash = GlobalWebContext.GetUserCanTrash(p_oFolderType);
            ManageToolbar();
        }

        /// <summary>
        /// Notify for display mode changes
        /// </summary>
        /// <param name="p_oNewAppDisplayMode">new display mode</param>
        public void ChangeAppDisplayMode(AppDisplayMode p_oNewAppDisplayMode)
        {
            AppDisplayMode = p_oNewAppDisplayMode;
            ManageToolbar();
        }

        /// <summary>
        /// Set the IsEnabled property of a ribbon bar button.
        /// </summary>
        /// <param name="p_oItem">Button to</param>
        /// <param name="p_bIsEnabled">true or false</param>
        /// <param name="bypassUserRights">if set to <c>true</c> [bypass user rights].</param>
        public void SetAvailability(DocumentRibbonBarMenuItems p_oItem, bool p_bIsEnabled, bool bypassUserRights = false)
        {
            ButtonViewModel l_oRibbonButton = FindItemByName(p_oItem.ToString());

            if (l_oRibbonButton != null)
            {
                if (!bypassUserRights)
                {
                    if (m_oCanImport.Contains(p_oItem) && CanImport)
                    {
                        l_oRibbonButton.IsEnabled = p_bIsEnabled;
                        if (l_oRibbonButton.IsQuickAccess)
                            SetQuickAccessButton(p_oItem.ToString(), p_bIsEnabled);
                    }
                    else if (m_oCanDelete.Contains(p_oItem) && CanDelete)
                    {
                        l_oRibbonButton.IsEnabled = p_bIsEnabled;
                        if (l_oRibbonButton.IsQuickAccess)
                            SetQuickAccessButton(p_oItem.ToString(), p_bIsEnabled);
                    }
                    else if (m_oCanDownload.Contains(p_oItem) && CanDownload)
                    {
                        l_oRibbonButton.IsEnabled = p_bIsEnabled;
                        if (l_oRibbonButton.IsQuickAccess)
                            SetQuickAccessButton(p_oItem.ToString(), p_bIsEnabled);
                    }
                    else if (m_oCanPrint.Contains(p_oItem) && CanPrint)
                    {
                        l_oRibbonButton.IsEnabled = p_bIsEnabled;
                        if (l_oRibbonButton.IsQuickAccess)
                            SetQuickAccessButton(p_oItem.ToString(), p_bIsEnabled);
                    }
                    else if (m_oCanSendMail.Contains(p_oItem) && CanSendMail)
                    {
                        l_oRibbonButton.IsEnabled = p_bIsEnabled;
                        if (l_oRibbonButton.IsQuickAccess)
                            SetQuickAccessButton(p_oItem.ToString(), p_bIsEnabled);
                    }
                    else
                    {
                        l_oRibbonButton.IsEnabled = p_bIsEnabled;
                        if (l_oRibbonButton.IsQuickAccess)
                            SetQuickAccessButton(p_oItem.ToString(), p_bIsEnabled);
                    }
                }
                else
                {
                    l_oRibbonButton.IsEnabled = p_bIsEnabled;

                    if (l_oRibbonButton.IsQuickAccess)
                        SetQuickAccessButton(p_oItem.ToString(), p_bIsEnabled);
                }
            }
        }

        #endregion

        #region Private

        /// <summary>
        /// Gets the quick access button.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="isEnabled">if set to <c>true</c> [is enabled].</param>
        private void SetQuickAccessButton(string name, bool isEnabled)
        {
            foreach (ButtonViewModel item in DocumentQuickAccessElement.Items)
            {
                if (item.GetType() == typeof(ButtonViewModel))
                {
                    if (item.Name == name)
                    {
                        item.IsEnabled = isEnabled;
                    }
                }
            }
        }

        /// <summary>
        /// Finds the name of the item by.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        private ButtonViewModel FindItemByName(string name)
        {
            foreach (TabViewModel tab in DocumentRibbonbarElement.Items)
            {
                foreach (GroupViewModel group in tab.Groups)
                {
                    foreach (var item in group.Buttons)
                    {
                        if (item.GetType() == typeof(ButtonGroupViewModel))
                        {
                            foreach (ButtonViewModel button in ((ButtonGroupViewModel)item).Buttons.Where(button => button.Name == name))
                            {
                                return button;
                            }
                        }
                        else if (item.GetType() == typeof(DropDownButtonViewModel))
                        {
                            if (item.Name == name)
                            {
                                return item;
                            }

                            foreach (MenuItemViewModel menuitem in ((DropDownButtonViewModel)item).MenuItems.Where(menuitem => menuitem.Name == name))
                            {
                                return menuitem;
                            }
                        }
                        else if (item.GetType() == typeof(ButtonViewModel))
                        {
                            if (item.Name == name)
                            {
                                return item;
                            }
                        }
                    }
                }
            }
            return null;
        }

        /// <summary>
        /// This is the common handler raised for every clicks in this ribbon bar
        /// IMPORTANT!! The name of the buttonSource in the XAML must be one of the DocumentRibbonBarMenuItems enumeration
        /// </summary>
        /// <param name="buttonSource">The button source.</param>
        private void RaiseClickEvent(string buttonSource)
        {
            DocumentRibbonBarMenuItems l_oDocumentRibbonBarMenuItem;
            if (Enum.TryParse(buttonSource, out l_oDocumentRibbonBarMenuItem))
            {
                this.DocumentRibbonBarEvent(this,
                    new DocumentRibbonBarEventArgs
                    {
                        DocumentRibbonBarMenuItem = l_oDocumentRibbonBarMenuItem
                    });
            }
        }

        /// <summary>
        /// Gets the path.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        private string GetPath(string fileName)
        {
            return string.Format(format, fileName);
        }

        /// <summary>
        /// Hides the minimized popup.
        /// </summary>
        public void HideMinimizedPopup()
        {
            //Do not remove this code, this an artefact to hide the fucking popup!!!!!!
            this.DocumentRibbonbarElement.IsMinimized = false;
            this.DocumentRibbonbarElement.IsMinimized = true;
        }


        #endregion

        #region Toolbar Creation

        /// <summary>
        /// Builds the too bar.
        /// </summary>
        private void BuildToolbar()
        {
            _tabs = new ObservableCollection<TabViewModel>();
            _quickAccessButtons = new ObservableCollection<ButtonViewModel>();

            TabViewModel homeTab = new TabViewModel();
            homeTab.Text = Resx.GetLabel(ResxCommon.DocumentToolbar_TabLabel);

            switch (AppDisplayMode)
            {
                case AppDisplayMode.AddDocument:
                case AppDisplayMode.Import:
                case AppDisplayMode.ImportDirectory:
                    homeTab.Groups.Add(GetImportGroup());
                    homeTab.Groups.Add(GetViewModeGroup());
                    homeTab.Groups.Add(GetDisplayGroup());
                    homeTab.Groups.Add(GetProcessingGroup());
                    homeTab.Groups.Add(GetSearchGroup());
                    homeTab.Groups.Add(GetPluginGroup());
                    break;

                case AppDisplayMode.Search:
                    homeTab.Groups.Add(GetClipboardGroup());
                    homeTab.Groups.Add(GetViewModeGroup());
                    homeTab.Groups.Add(GetDisplayGroup());
                    homeTab.Groups.Add(GetProcessingGroup());
                    homeTab.Groups.Add(GetActionGroup());
                    homeTab.Groups.Add(GetSearchGroup());
                    break;

                case AppDisplayMode.Flow:
                    homeTab.Groups.Add(GetClipboardGroup());
                    homeTab.Groups.Add(GetViewModeGroup());
                    homeTab.Groups.Add(GetDisplayGroup());
                    homeTab.Groups.Add(GetProcessingGroup());
                    homeTab.Groups.Add(GetActionGroup());
                    homeTab.Groups.Add(GetSearchGroup());
                    break;

                case AppDisplayMode.None:
                    homeTab.Groups.Add(GetImportGroup());
                    homeTab.Groups.Add(GetViewModeGroup());
                    homeTab.Groups.Add(GetDisplayGroup());
                    homeTab.Groups.Add(GetProcessingGroup());
                    homeTab.Groups.Add(GetSearchGroup());
                    homeTab.Groups.Add(GetPluginGroup());
                    break;

                case AppDisplayMode.SearchNone:
                    homeTab.Groups.Add(GetClipboardGroup());
                    homeTab.Groups.Add(GetViewModeGroup());
                    homeTab.Groups.Add(GetDisplayGroup());
                    homeTab.Groups.Add(GetProcessingGroup());
                    homeTab.Groups.Add(GetActionGroup());
                    homeTab.Groups.Add(GetSearchGroup());
                    //homeTab.Groups.Add(GetPluginGroup());
                    break;
            }

            _tabs.Add(homeTab);
        }

        /// <summary>
        /// Gets the clipboard group.
        /// </summary>
        /// <returns></returns>
        private GroupViewModel GetClipboardGroup()
        {
            GroupViewModel group = new GroupViewModel();
            group.Text = Resx.GetLabel(ResxCommon.EDITION);

            ButtonViewModel split = new ButtonViewModel();
            split.Text = Resx.GetLabel(ResxCommon.PASTE);
            split.Name = "Paste";
            split.Size = ButtonSize.Large;
            split.LargeImage = GetPath("Paste.png");
            split.SmallImage = GetPath("Paste16.png");
            split.IsEnabled = false;
            group.Buttons.Add(split);

            ButtonGroupViewModel buttonsGroup = new ButtonGroupViewModel();
            buttonsGroup.Buttons.Add(GetButton("Cut", "Cut", Resx.GetLabel(ResxCommon.CUT)));
            buttonsGroup.Buttons.Add(GetButton("Copy", "Copy", Resx.GetLabel(ResxCommon.COPY)));
            group.Buttons.Add(buttonsGroup);

            //buttonsGroup = new ButtonGroupViewModel();
            //buttonsGroup.Buttons.Add(GetButton("CheckOut", "Edit", Resx.GetLabel(ResxCommon.EDIT), ButtonSize.Large, true));
            //buttonsGroup.Buttons.Add(GetButton("CheckIn", "Publish", Resx.GetLabel(ResxCommon.PUBLISH), ButtonSize.Large, true));
            //group.Buttons.Add(buttonsGroup);
            return group;
        }

        /// <summary>
        /// Gets the import group.
        /// </summary>
        /// <returns></returns>
        private GroupViewModel GetImportGroup()
        {
            GroupViewModel group = new GroupViewModel();
            group.Text = Resx.GetLabel(ResxCommon.IMPORTATION);

            group.Buttons.Add(GetButton("Import", "Import", Resx.GetLabel(ResxCommon.IMPORTATION), ButtonSize.Large, true));

            //Add this the scan button only if the user have rioscan
            if (GlobalWebContext.ClientScan)
                group.Buttons.Add(GetButton("Scan", "Scanner", Resx.GetLabel("Scanning"), ButtonSize.Large, true));

            return group;
        }

        /// <summary>
        /// Gets the view mode group.
        /// </summary>
        /// <returns></returns>
        private GroupViewModel GetViewModeGroup()
        {
            GroupViewModel group = new GroupViewModel();
            group.Text = Resx.GetLabel(ResxCommon.MODE);

            group.Buttons.Add(GetButton("DocumentMode", "Single", Resx.GetLabel(ResxCommon.DISPLAYVIEWERMODE), ButtonSize.Large, true));
            group.Buttons.Add(GetButton("ThumbnailsMode", "Thumbnail", Resx.GetLabel(ResxCommon.DISPLAYTHUMBNAILMODE), ButtonSize.Large, true));
            group.Buttons.Add(GetButton("ListMode", "List", Resx.GetLabel(ResxCommon.DISPLAYLISTMODE), ButtonSize.Large, true));

            return group;
        }

        /// <summary>
        /// Gets the display group.
        /// </summary>
        /// <returns></returns>
        private GroupViewModel GetDisplayGroup()
        {
            GroupViewModel group = new GroupViewModel();
            group.Text = Resx.GetLabel("Displaying");

            ButtonGroupViewModel buttonsGroup1 = new ButtonGroupViewModel();
            buttonsGroup1.IsSmallGroup = true;

            bool isFitToQuickAccess = false;
            bool isSelectToQuickAccess = false;
            bool isZoomToQuickAccess = false;
            switch (ViewMode)
            {
                case AppViewMode.List:
                    isSelectToQuickAccess = true;
                    break;
                case AppViewMode.Thumbnail:
                    isSelectToQuickAccess = true;
                    break;
                case AppViewMode.Single:
                    isFitToQuickAccess = true;
                    isZoomToQuickAccess = true;
                    break;
            }

            buttonsGroup1.Buttons.Add(GetButton("FitHeight", "fitHeight", Resx.GetLabel(ResxCommon.FIT_HEIGHT), ButtonSize.Medium, isFitToQuickAccess, true));
            buttonsGroup1.Buttons.Add(GetButton("FitWidth", "fitWidth", Resx.GetLabel(ResxCommon.FIT_WIDTH), ButtonSize.Medium, isFitToQuickAccess, true));

            //uncomment: 9.
            buttonsGroup1.Buttons.Add(GetButton("FolderLink", "folderlink", Resx.GetLabel(ResxCommon.FOLDER_LINK), ButtonSize.Medium, false, false));

            group.Buttons.Add(buttonsGroup1);

            ButtonGroupViewModel buttonsGroup2 = new ButtonGroupViewModel();
            buttonsGroup2.IsSmallGroup = true;
            buttonsGroup2.Buttons.Add(GetButton("SelectAll", "selectall", Resx.GetLabel("SelectAll"), ButtonSize.Medium, isSelectToQuickAccess, true));
            buttonsGroup2.Buttons.Add(GetButton("SelectNone", "selectNone", Resx.GetLabel("UnSelectAll"), ButtonSize.Medium, isSelectToQuickAccess, true));
            group.Buttons.Add(buttonsGroup2);

            ButtonGroupViewModel buttonsGroup3 = new ButtonGroupViewModel();
            buttonsGroup3.IsSmallGroup = true;
            buttonsGroup3.Buttons.Add(GetButton("ZoomIn", "Zoom_In", Resx.GetLabel(ResxCommon.ZOOMIN), ButtonSize.Medium, isZoomToQuickAccess, true));
            buttonsGroup3.Buttons.Add(GetButton("ZoomOut", "Zoom_Out", Resx.GetLabel(ResxCommon.ZOOMOUT), ButtonSize.Medium, isZoomToQuickAccess, true));
            group.Buttons.Add(buttonsGroup3);

            return group;
        }

        /// <summary>
        /// Gets the processing group.
        /// </summary>
        /// <returns></returns>
        private GroupViewModel GetProcessingGroup()
        {
            GroupViewModel group = new GroupViewModel();
            group.Text = Resx.GetLabel("Workflow_Treatments");

            //Merge PDF
            DropDownButtonViewModel convertMenu = new DropDownButtonViewModel();
            convertMenu.Text = Resx.GetLabel("PDFConversion");
            convertMenu.Name = "MergePDFMenu";
            convertMenu.Size = ButtonSize.Large;
            convertMenu.LargeImage = GetPath("Pdf.png");
            convertMenu.SmallImage = GetPath("Pdf16.png");

            MenuItemViewModel mergeMenu = new MenuItemViewModel();
            mergeMenu.Text = Resx.GetLabel(ResxCommon.MERGE_PDF);
            mergeMenu.Name = "MergePDF";
            mergeMenu.IsEnabled = false;
            mergeMenu.IconUrl = new Uri("../../Assets/Images/Viewer/Pdf16.png", UriKind.Relative);
            convertMenu.MenuItems.Add(mergeMenu);

            MenuItemViewModel explodeMenu = new MenuItemViewModel();
            explodeMenu.Text = Resx.GetLabel(ResxCommon.EXPLODE_PDF);
            explodeMenu.Name = "SplitPDF";
            explodeMenu.IsEnabled = false;
            explodeMenu.IconUrl = new Uri("../../Assets/Images/Viewer/Pdf16.png", UriKind.Relative);
            convertMenu.MenuItems.Add(explodeMenu);
            group.Buttons.Add(convertMenu);


            //Rotate 
            ButtonGroupViewModel buttonsGroup1 = new ButtonGroupViewModel();
            buttonsGroup1.IsSmallGroup = true;
            buttonsGroup1.Buttons.Add(GetButton("RotateLeft", "Rotate_Left", Resx.GetLabel(ResxCommon.ROTATELEFT), ButtonSize.Medium, true, false));
            buttonsGroup1.Buttons.Add(GetButton("RotateRight", "Rotate_Right", Resx.GetLabel(ResxCommon.ROTATERIGHT), ButtonSize.Medium, true, false));
            buttonsGroup1.Buttons.Add(GetButton("Delete", "Delete", Resx.GetLabel(ResxCommon.DELETE), ButtonSize.Medium, true));
            group.Buttons.Add(buttonsGroup1);

            //Download - SendMail
            ButtonGroupViewModel buttonsGroup2 = new ButtonGroupViewModel();
            buttonsGroup2.IsSmallGroup = true;
            buttonsGroup2.Buttons.Add(GetButton("Download", "Save", Resx.GetLabel(ResxCommon.DOWNLOAD), ButtonSize.Medium));
            buttonsGroup2.Buttons.Add(GetButton("SendEmail", "NewMail", Resx.GetLabel(ResxCommon.SEND_BY_MAIL), ButtonSize.Medium));
            buttonsGroup2.Buttons.Add(GetButton("SaveModifications", "saveimage", Resx.GetLabel(ResxCommon.SAVE_MODIFICATION), ButtonSize.Medium, true, false));
            group.Buttons.Add(buttonsGroup2);

            return group;
        }

        /// <summary>
        /// Gets the search group.
        /// </summary>
        /// <returns></returns>
        private GroupViewModel GetSearchGroup()
        {
            GroupViewModel group = new GroupViewModel();
            group.Text = Resx.GetLabel("MainSearchHeaderTab");

            //Download - SendMail
            ButtonGroupViewModel search = new ButtonGroupViewModel();
            search.IsSmallGroup = true;

            search.Buttons.Add(GetButton("SearchPrevious", "search-previous", Resx.GetLabel("Previous")));
            search.Buttons.Add(GetButton("SearchNext", "search-next", Resx.GetLabel("Next")));
            group.Buttons.Add(search);

            return group;
        }

        /// <summary>
        /// Gets the plugin group.
        /// </summary>
        /// <returns></returns>
        private GroupViewModel GetPluginGroup()
        {
            GroupViewModel group = new GroupViewModel();
            group.Text = Resx.GetLabel("Directory");

            //Download - SendMail
            ButtonGroupViewModel buttonsGroup3 = new ButtonGroupViewModel();
            buttonsGroup3.Buttons.Add(GetButton("OpenDirectory", "OpenDirectory", Resx.GetLabel(ResxListVignetteSearch.OPEN_DIRECTORY), ButtonSize.Large, true, false));
            buttonsGroup3.Buttons.Add(GetButton("ReturnDirectory", "ReturnDirectory", Resx.GetLabel(ResxListVignetteSearch.RETURN_DIRECTORY), ButtonSize.Large, true, false));
            group.Buttons.Add(buttonsGroup3);

            return group;
        }

        /// <summary>
        /// Gets the action group.
        /// </summary>
        /// <returns></returns>
        private GroupViewModel GetActionGroup()
        {
            GroupViewModel group = new GroupViewModel();
            group.Text = Resx.GetLabel(ResxCommon.ACTIONS);

            //Add Document
            group.Buttons.Add(GetButton("AddDocument", "Add_Document", Resx.GetLabel(ResxFolder.ADD_DOCUMENT), ButtonSize.Large));

            //Ventilate
            group.Buttons.Add(GetButton("Ventilate", "Ventil", Resx.GetLabel(ResxCommon.VENTIL), ButtonSize.Large));

            //Print
            DropDownButtonViewModel print = new DropDownButtonViewModel();
            print.Text = Resx.GetLabel(ResxCommon.PRINT);
            print.Name = "PrintMenu";
            print.Size = ButtonSize.Large;
            print.LargeImage = GetPath("Printer.png");
            print.SmallImage = GetPath("Printer16.png");

            MenuItemViewModel printMenu = new MenuItemViewModel();
            printMenu.Text = Resx.GetLabel(ResxCommon.PRINT);
            printMenu.Name = "Print";
            printMenu.IconUrl = new Uri("../../Assets/Images/Viewer/Printer16.png", UriKind.Relative);
            print.MenuItems.Add(printMenu);

            MenuItemViewModel documentPrintMenu = new MenuItemViewModel();
            documentPrintMenu.Text = Resx.GetLabel(ResxCommon.DOCUMENT_PRINT);
            documentPrintMenu.Name = "DocumentPrint";
            documentPrintMenu.IconUrl = new Uri("../../Assets/Images/Viewer/DocumentPrint16.png", UriKind.Relative);
            print.MenuItems.Add(documentPrintMenu);

            group.Buttons.Add(print);

            return group;
        }

        /// <summary>
        /// Gets the button.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="image">The image.</param>
        /// <param name="text">The text.</param>
        /// <param name="size">The size.</param>
        /// <param name="addToQuickAccess">if set to <c>true</c> [add to quick access].</param>
        /// <param name="isVisibleWhenDisabled"></param>
        /// <returns></returns>
        private ButtonViewModel GetButton(string name, string image, string text, ButtonSize size, bool addToQuickAccess = false, bool isVisibleWhenDisabled = true)
        {
            ButtonViewModel b = new ButtonViewModel
            {
                SmallImage = GetPath(string.Format("{0}16.png", image)),
                Name = name,
                LargeImage = GetPath(string.Format("{0}.png", image)),
                Text = text,
                Size = size,
                IsQuickAccess = addToQuickAccess,
                isVisibleWhenDisabled = isVisibleWhenDisabled,
                IsEnabled = false
            };

            if (addToQuickAccess)
                _quickAccessButtons.Add(b);

            return b;
        }

        /// <summary>
        /// Gets the button.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="image">The image.</param>
        /// <param name="text">The text.</param>
        /// <param name="isQuickAccess">if set to <c>true</c> [is quick access].</param>
        /// <returns></returns>
        private ButtonViewModel GetButton(string name, string image, string text, bool isQuickAccess = false)
        {
            return GetButton(name, image, text, ButtonSize.Small, isQuickAccess);
        }

        #endregion

    }
}